﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace ColorClusteringSOM.Visualation
{
    /// <summary>
    /// Trida ktera pomaha k vizualizaci
    /// </summary>
    class VisHelper
    {

        /// <summary>
        /// Metoda, ktera pomuze najit okraje nejake mnoziny
        /// </summary>
        public void FindEdges()
        {
        }

        public void /*NeuronRough[,]*/ ListToArray(List<NeuronRough> list)
        {
            NeuronRough[,] array = new NeuronRough[list.Count,list.Count];

            foreach (NeuronRough neuron in list)
            {
                array[neuron.X, neuron.Y] = neuron;
            }
            print(array);
            //return array;
        }

        public void print(NeuronRough[,] ar)
        {
            for (int i = 0; i < ar.Length; i++)
            {
                for (int j = 0; j < ar.GetLength(0); j++)
                {
                    if (ar[i, j] != null)
                    {
                        Console.Write("*");
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                }
                Console.WriteLine();
                
            }
        }



        /// <summary>
        /// Vytiskene jednotlive oblasti
        /// </summary>
        internal void PrintMatrix(List<NeuronRough> lower)
        {
            int xOld = -1;
            int yOld = -1;
           String str = "\n\nStart...\n";
            
            
            
            foreach (NeuronRough neuron in lower)
            {
                for (int i = 0; i < lower.Count; i++)
                {

                    
                }

                if (neuron.X <= xOld)
                {
                    str += "-END\n";
                    xOld = -1;
                }
                else if(neuron.X > xOld )
                {
                    str += " * ";
                    xOld = neuron.X;
                }


            }

            Console.WriteLine(str);
        }

        /// <summary>
        /// Ukladani screanu obrazovky
        /// </summary>
        /// <param name="control"></param>
        /// <param name="fileName"></param>
        public static void SaveAsBitmap(Control control, string fileName)
        {
            //getthe instance of the graphics from the control
            Graphics g = control.CreateGraphics();

            //new bitmap object to save the image
            Bitmap bmp = new Bitmap(control.Width, control.Height);

            //Drawing control to the bitmap
            control.DrawToBitmap(bmp, new Rectangle(0, 0, control.Width, control.Height));

            bmp.Save(fileName);
            bmp.Dispose();

        }
    
    }
}
